package com.fegin.api;

import com.fegin.api.service.Firend;
import com.fegin.api.service.IService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:RenPu
 * @Date: 2020/8/27 18:52
 * @Version: 1.0
 * @description:
 */


@RestController
@Slf4j
public class IServiceImpl implements IService {

    @Value("${server.port}")
    private String serverPort;


    @Override
    public String eurekaClientTest(String test) {

        return "This is +" + serverPort;
    }


    @Override
    public Firend testPostMethond(@RequestBody Firend firend) {

        log.info("You are my firend" + firend.getName());
        firend.setPort(serverPort);

        return firend;

    }

    @Override
    public String testPostMethond(List<String> stringList) {
        return null;
    }


    /**
     * 模拟超时的接口
     *
     * @param timeout
     * @return
     */
    @Override
    public String retry(@RequestParam("timeout") int timeout) {


        while (--timeout >= 0) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        log.info("retry-------------" + serverPort);

        return null;
    }


    /**
     * 测试hystrix的方法
     *
     * @return
     */
    @Override
    public String error() {
        throw new RuntimeException("blank sheep");
    }
}
